<?php

class MemberController extends CommonController{
	
	private $_model;
	
	public function __init(){
		
		$this->_model=K('Member');
	}
	
	public function login(){
		
		if(isset($_SESSION['uid']) && isset($_SESSION['username'])){
			go(U('Index/index'));
		}
		
		if(IS_POST){
			
			if(!$data=$this->_model->validate_login()) $this->error($this->_model->error);
			
			$_SESSION['uid']=$data['uid'];
			$_SESSION['username']=Q('post.username');
			
			if(Q('post.tick')){
				setcookie(session_name(),session_id(),time() + 3600 *24 *7, '/');
			}else{
				setcookie(session_name(),session_id(),0,'/');
			}
			
			$this->success('登录成功');
		}
		
		$this->dis('login');
	}
	
	public function register(){
		
		if(IS_POST){
			if(!$this->_model->validate_register()) $this->error($this->_model->error);
			$this->success('注册成功');
		}
		
		$this->dis('register');
	}
	
	public function code(){
		$code=new Code;
		$code->show();
	}
	
	public function out(){
		session(NULL);
		
		$this->success('退出成功');
	}
	
	
}
